package org.jeecg.modules.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.system.entity.DetailInfo;
import org.jeecg.modules.system.vo.Ids;

import java.util.List;

/**
 * @Description: 明细表
 * @Author: jeecg-boot
 * @Date:   2025-04-25
 * @Version: V1.0
 */
@Mapper
public interface DetailInfoMapper extends BaseMapper<DetailInfo> {

    @Delete("delete from detail_info")
    void deleteAll();

    @Select("select c.id,c.idb  from (SELECT a.*,b.source as sourceb,b.debit as debitb,b.id as idb FROM \n" +
            "(\n" +
            "\t(SELECT * FROM detail_info WHERE source = \"应付帐款\" ORDER BY debit) a \n" +
            "\tLEFT JOIN \n" +
            "\t( SELECT* FROM detail_info WHERE source = \"EMS\"ORDER BY debit ) b \n" +
            "\tON a.detail_name = b.detail_name and a.rate = b.rate and abs(a.debit) = abs(b.debit)\n" +
            ")) c WHERE abs(c.debit) = abs(c.debitb)")
    List<Ids> findSameIds();
}
